# Guess number
import random
import turtle

# set coordinate
turtle.setworldcoordinates(0, 1000, 1000, 0)
line_pos = 0

def show_hit(text, color="black"):
    """show some hit"""
    global line_pos
    font_song = ("宋体", 18)
    line_height = 50

    turtle.up()
    line_pos += line_height
    turtle.goto(0, line_pos)
    turtle.color(color)
    turtle.write(text, font=font_song)
    return None

# Ask for player's name
player = turtle.textinput("Guess Number", "Hello! What's your name?")

# generate a number for guessing
target = random.randrange(0, 20)

# show some prompt
show_hit(f"Hello, {player}!", "green")
show_hit("There's a integer not greater than 20")
show_hit("Can you guess it?")

# guess loop
while True:
    guess = turtle.numinput("Guess Number", "Take a guess.")
    guess = round(guess)
    if guess > target:
        show_hit(f"Your guess '{guess}' is greater than the number.", "darkblue")
    elif guess < target:
        show_hit(f"Your guess '{guess}' is less than the number.", "blue")
    else:
        show_hit(f"Yes! {player}, You're right, the number is {guess}", color="red")
        break

turtle.done()